package net;

import java.io.*;
import java.net.*;

public class ConexionAServer {
	
	private URL baseUrl;
	private URLConnection cnx;
	private Authenticator au;
	private boolean usaAuth;
	
	public void inicializarConexion(String urlString) throws MalformedURLException {
		this.baseUrl = new URL(urlString);
		this.usaAuth = false;
	}
	
	public void defineAuth(String user, String pass){
		final String u = ""+ user;
		final String p = ""+ pass;
		this.au= new Authenticator() {
	          protected PasswordAuthentication  
	             getPasswordAuthentication() {  
	             return new PasswordAuthentication  
	               (u, p.toCharArray());  
	          }  
	       };  
	}
	
	public void usarAuth(boolean usarAuthSiNo){
		this.usaAuth = usarAuthSiNo;
	}
	
	public int getPuerto(){
		if ( baseUrl.getPort() == -1) return baseUrl.getDefaultPort();
		else return baseUrl.getPort();
	}
	
	public void setCache(boolean b){
		cnx.setUseCaches(b);
	}
	
	public void usarProxy(boolean b){
		this.usaAuth = b;
	}
	
	public void setProxy(String p){
		
	}

}
